<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>倒计时</title>
</head>
<body>
    <div>
        距活动结束：<span id="day"></span>天<span id="hour"></span>时<span id="minute"></span>分<span id="second"></span>秒
    </div>
    
    <script>
        function countdown(){
            var endtime=new Date('2018/10/10 00:00:00');
            var timer=setInterval(autoplay,1000)
            function autoplay(){
                var data=new Date();
                var ms=endtime.getTime()-data.getTime();
                var s=parseInt(ms/1000);
                var day=parseInt(s/3600/24);
                var hour=parseInt(s/3600%24);
                var minute=parseInt(s/60%60);
                var second=parseInt(s%60);
                if(day<=0&&hour<=0&&minute<=0&&second<=0){
                    day=0;
                    hour=0;
                    minute=0;
                    second=0;
                    clearInterval(timer);
                }
                day=day<10?'0'+day:day;
                hour=hour<10?'0'+hour:hour;
                minute=minute<10?'0'+minute:minute;
                second=second<10?'0'+second:second;
                document.getElementById('day').innerHTML=day;
                document.getElementById('hour').innerHTML=hour;
                document.getElementById('minute').innerHTML=minute;
                document.getElementById('second').innerHTML=second;
            }   
        }
        countdown();
    </script>
</body>
</html>